﻿var sel = 1;

function Selected(selected) {

    var trekkingDays = document.getElementById('trekkingDays');
    
    var yourItinerary = document.getElementById('yourItinerary');
    var keySpots = document.getElementById('keySpots');
    var finalize = document.getElementById('finalize');
    var submitbutton = document.getElementById('submitButton');

    submitbutton.style.visibility = "hidden";

    var saveButton = document.getElementById('saveButton');
    saveButton.style.visibility = "visible";

    var iframe = document.getElementById('iframe');

    iframe.scrolling = "no";

    trekkingDays.style.background = 'none repeat scroll 0 0 #F0F0F0';
    trekkingDays.style.color = '#696969';

    yourItinerary.style.background = 'none repeat scroll 0 0 #F0F0F0';
    yourItinerary.style.color = '#696969';

    keySpots.style.background = 'none repeat scroll 0 0 #F0F0F0';
    keySpots.style.color = '#696969';

    finalize.style.background = 'none repeat scroll 0 0 #F0F0F0';
    finalize.style.color = '#696969';
    sel = selected;

    switch (selected) {

        case 1:
            trekkingDays.style.background = 'none repeat scroll 0 0 #699e24';
            trekkingDays.style.color = '#fff';
            iframe.style.height = "700px";
            iframe.style.width = "101%";
            iframe.src = 'TrekkingDays.html';
            break;
        case 2:
            var siderbar = document.getElementById('sidebar');
            yourItinerary.style.background = 'none repeat scroll 0 0 #699e24';
            yourItinerary.style.color = '#fff';
            iframe.style.height = "550px";
            iframe.style.width = "72%";
            iframe.scrolling = "no";
            iframe.src = 'GoogleMaps.html';
            break;
        case 3:
            var siderbar = document.getElementById('sidebar');
            yourItinerary.style.background = 'none repeat scroll 0 0 #699e24';
            yourItinerary.style.color = '#fff';
            iframe.style.height = "550px";
            iframe.style.width = "72%";
            iframe.scrolling = "no";
            iframe.src = 'GoogleMaps.html';
            break;
        case 4:
            finalize.style.background = 'none repeat scroll 0 0 #699e24';
            finalize.style.color = '#fff';
            iframe.style.height = "700px"
            iframe.style.width = "100%"
            iframe.scrolling = "yes";
            saveButton.style.visibility = "hidden";
            submitButton.style.visibility = "visible";
            iframe.src = 'finalize.html'
            break;
    }
}

function SaveInformation() {

    switch (sel.toString()) {
        case "1":
            SaveTrekkingInformation();
            break;

        case "2":
            SaveMapInformation();
            break;

        case "3":
            SaveSpot();
            break;
    }

    Selected(sel + 1);
}

function submit2() {
//    debugger;
    ExploreAndShare.WebServices.ShareWebService.SaveGeneralInformation("asdasd");
}

function SaveTrekkingInformation() {

    var gtc = Sys.Net.WebServiceProxy._generateTypedConstructor;
    Type.registerNamespace('ExploreAndShare.Models.Entities');

    if (typeof (ExploreAndShare.Models.Entities.Trekking) === 'undefined') {
        ExploreAndShare.Models.Entities.Trekking = gtc("ExploreAndShare.Models.Entities.Trekking");
        ExploreAndShare.Models.Entities.Trekking.registerClass('ExploreAndShare.Models.Entities.Trekking');
    }

    var trekkingInformation = new ExploreAndShare.Models.Entities.Trekking();

    var trekingInformationPage = document.getElementById('iframe').contentWindow.document;

    trekkingInformation.Title = trekingInformationPage.getElementById('title').value;
    trekkingInformation.SubTitle = trekingInformationPage.getElementById('subTitle').value;

    var difficulty = trekingInformationPage.getElementById('difficulty');

    for (var i = 0, limit = difficulty.length; i < limit; ++i) {

        if (difficulty[i].selected) {
            trekkingInformation.Difficulty = difficulty.value;
            break;
        }
    }

    var duration = trekingInformationPage.getElementById('duration');

    for (var i = 0, limit = duration.length; i < limit; ++i) {

        if (difficulty[i].selected) {
            trekkingInformation.Duration = duration.value;
            break;
        }
    }

    //Activity Section

    var activity = trekingInformationPage.getElementById('activity');

    var activityDictionary = {};

    for (var i = 0, limit = activity.childNodes.length; i < limit; ++i) {

        var nodes = activity.childNodes[i].childNodes;

        for (var j = 0, nodelimit = nodes.length; j < nodelimit; ++j) {

            if (nodes[j].type == "checkbox") {
                activityDictionary[nodes[j].value] = nodes[j].checked;
            }
        }
    }

    //End Activity Section

    trekkingInformation.Activity = activityDictionary;
    trekkingInformation.Open = trekingInformationPage.getElementById('opened').checked ? "openSource" : "closeSource";
    trekkingInformation.OverView = trekingInformationPage.getElementById('overView').value;
//    trekkingInformation.Image = todo;

    ExploreAndShare.WebServices.ShareWebService.SaveGeneralInformation(trekkingInformation);
}

function SaveMapInformation() {
    var iframe = document.getElementById('iframe');
    var myMap = iframe.document.getElementById('map');

    var gtc = Sys.Net.WebServiceProxy._generateTypedConstructor;
    Type.registerNamespace('ExploreAndShare.Models.Entities');

    if (typeof (ExploreAndShare.Models.Dtos.Map) === 'undefined') {
        ExploreAndShare.Models.Entities.Map = gtc("ExploreAndShare.Models.Entities.Map");
        ExploreAndShare.Models.Entities.Map.registerClass('ExploreAndShare.Models.Entities.Map');
    }
    var map = new ExploreAndShare.Models.Entities.Map();

    ExploreAndShare.WebServices.ShareWebService.SaveMapInformation(ObjectToSave);
}

function SaveSpot() {
    ExploreAndShare.WebServices.ShareWebService.SaveSpot(ObjectToSave);
}

function SaveAndSubmit() {
    var gtc = Sys.Net.WebServiceProxy._generateTypedConstructor;
    Type.registerNamespace('ExploreAndShare.Models.Dtos');

    if (typeof (ExploreAndShare.Models.Dtos.TrekkingFinalizeDtoForSave) === 'undefined') {
        ExploreAndShare.Models.Dtos.TrekkingFinalizeDtoForSave = gtc("ExploreAndShare.Models.Dtos.TrekkingFinalizeDtoForSave");
        ExploreAndShare.Models.Dtos.TrekkingFinalizeDtoForSave.registerClass('ExploreAndShare.Models.Dtos.TrekkingFinalizeDtoForSave');
    }

    var trekkingFinalizeDtoForSave = new ExploreAndShare.Models.Dtos.TrekkingFinalizeDtoForSave();
    var trekingFinalizePage = document.getElementById('iframe').contentWindow.document;

    //Location Section

    trekkingFinalizeDtoForSave.City = trekingFinalizePage.getElementById('City').value;
    trekkingFinalizeDtoForSave.State = trekingFinalizePage.getElementById('State').value;
    trekkingFinalizeDtoForSave.Region = trekingFinalizePage.getElementById('Region').value;

    // Guide Section

    trekkingFinalizeDtoForSave.LastName = trekingFinalizePage.getElementById('lastName').value;
    trekkingFinalizeDtoForSave.Surname = trekingFinalizePage.getElementById('surName').value;
    trekkingFinalizeDtoForSave.Email = trekingFinalizePage.getElementById('email').value;
    trekkingFinalizeDtoForSave.Comments = trekingFinalizePage.getElementById('comments').value;

    //URL Section
    trekkingFinalizeDtoForSave.Url = trekingFinalizePage.getElementById('url').value;

    var typeOfUrl = trekingFinalizePage.getElementById('typeOfUrl');

    var typeOfUrlDictionary = {};

    typeOfUrlDictionary['shop'] = trekingFinalizePage.getElementById('shop').checked;
    typeOfUrlDictionary['restaurant'] = trekingFinalizePage.getElementById('restaurant').checked;
    typeOfUrlDictionary['accommo'] = trekingFinalizePage.getElementById('accommo').checked;
    trekkingFinalizeDtoForSave.TypeOfUrl = typeOfUrlDictionary;
    trekkingFinalizeDtoForSave.ComentsTypeOfUrl = trekingFinalizePage.getElementById('comentsTypeOfUrl').value;
    trekkingFinalizeDtoForSave.Budget = trekingFinalizePage.getElementById('budget').value;

    //Tips Section

    trekkingFinalizeDtoForSave.Budget = trekingFinalizePage.getElementById('budget').value;
    trekkingFinalizeDtoForSave.Admin = trekingFinalizePage.getElementById('admin').value;
    trekkingFinalizeDtoForSave.Equipment = trekingFinalizePage.getElementById('equipment').value;
    trekkingFinalizeDtoForSave.Others = trekingFinalizePage.getElementById('others').value;

    ExploreAndShare.WebServices.ShareWebService.Finalize(trekkingFinalizeDtoForSave);
}